package ucn.dmf83.sc.workshop1.group3.UILayer;

import ucn.dmf83.sc.workshop1.group3.ControlLayer.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class MainMenu
{
    private static AddressBookCtrl controller;
    
	private static void clear() {
		int i = 0;
		while(i < 25)
		{
			System.out.println("");
			i++;
		}
	}
    
    public MainMenu()
    {
    	controller = new AddressBookCtrl();
        showMenu();
    }
       
    public static void main(String[] args) {
    	controller = new AddressBookCtrl();
        showMenu();
    }
    
	private static void showHeader() {
		clear();
   	 	System.out.println("------------------------------------------------");
        System.out.println("-                                              -");
        System.out.println("-    AddressBook v0.1 by Group3 Inc.           -");
        System.out.println("-                                              -");
        System.out.println("------------------------------------------------");
	}
   
    public static void showMenu()
    {
    	showHeader();
        int choice = writeMainMenu();
        	
        switch(choice) {
        case 1:
            PeopleMenu.showMenu(controller);
        case 2:
            DisksMenu.showMenu(controller);
        case 3:
            LoansMenu.showMenu(controller);
        case 4:
        	clear();
            System.out.println("Thanks for using AddressBook!");
            System.exit(1);
        default:
            System.out.println("Invalid selection, please try again!");
            showMenu();
        }
    }

    private static int writeMainMenu() {
        System.out.println("\n\n\f *** MainMenu ***");
        System.out.println(" 1. AddressBook");
        System.out.println(" 2. DVDs");
        System.out.println(" 3. Loans");
        System.out.println(" 4. Close");
        System.out.print("\n \n Please type in the number of your requested option: ");
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String data = null;
 		try {
 			data = br.readLine();
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
 		
 		int i = 0;
 		
 		try {
 			i = Integer.parseInt(data);
 		}
 		catch(Exception e) {
 			e.printStackTrace();
 		}
 		
        return i;
    }
    
}